import VueRouter from 'vue-router';
import Vue from 'vue';

import HomeView from '../pages/home/home.vue'
import AboutView from '../pages/about/about.vue'
Vue.use(VueRouter)

const routerContext = require.context('./modules', true, /\.js$/) // 获取路由模块的上下文

let autoRoute = []

// 获得路由的属性
routerContext.keys().forEach(route => {
    const routerModule =  routerContext(route) // 得到路由的模块
    
    // 兼容 import export 和 require module.export 两种规范
    
    autoRoute = [...autoRoute, ...(routerModule.default || routerModule)]
 });

const routes = [
  ...autoRoute,
  { path: '/', component: HomeView },
  { path: '/about', component: AboutView },
]





const router = new VueRouter({
    routes : routes
  })
export default router